import React from "react";
import { inject, observer } from "mobx-react";
import { message } from "antd";

const HOCStoreShareSet = (WrapComponent) => {
  @inject("setStoreInfo")
  @observer
  class ElementComponent extends React.Component {
    componentDidMount() {
      let { getShareSet } = this.props.setStoreInfo;
      //查询分享设置
      getShareSet().then((data) => {
        if (data.data.code === 200) {
          let allData = data.data.data[0];
          this.setForm(allData);
        } else {
          message.error("查询数据失败");
        }
      });
    }
    setForm = (obj) => {
      let { formOne, formTwo } = this.refs.form.refs;
      formOne.setFieldsValue(obj);
      formTwo.setFieldsValue(obj);
    };
    submit = () => {
        let {formOne, formTwo} = this.refs.form.refs
        let {updateShareSet} = this.props.setStoreInfo
      let key1 = [
        "sssFpt",
        "sssItthp",
        "sssIts",
        "sssLt",
        "sssItld",
        "sssLgt",
        "sssAbittlr",
        "sssSst",
        "sssItss",
        "sssSit",
      ];
      let key2 = [
        "sssSip",
        "sssHft",
        "sssIthfb",
        "sssHlt",
        "sssHl",
        "sssTopm",
        "sssItim",
        "sssCct",
        "sssItcc",
      ];
      let form1 = formOne.getFieldsValue(key1)
      let form2 = formTwo.getFieldsValue(key2)
      let form = {...form1, ...form2}
      form.sssId = 1
      updateShareSet(form).then(data=>{
          if (data.data.code === 200) {
              message.success('更新数据成功')
          }else{
              message.error('更新数据失败')
          }
      })
    };
    render() {
      let methods = {
        submit: this.submit,
      };
      return (
        <div>
          <WrapComponent ref="form" {...methods}></WrapComponent>
        </div>
      );
    }
  }
  return ElementComponent;
};

export default HOCStoreShareSet;
